﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EvincePayroll.Data;
using EvincePayroll.Utility;
using System.Net;
using EvinceUI;

namespace EvincePayroll.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/

        public ActionResult Login()
        {

            return View();
        }

        public ActionResult AuthenticateEmailId(string emailId)
        {

            bool result = false;
            if (emailId != "")
            {
                EvincePayrollService accountService = new EvincePayrollService(ServiceTypes.Account);
                result = accountService.AuthenticateEmail(emailId);
            }
            return Json(new { result }, JsonRequestBehavior.AllowGet);

        }

        //public ActionResult AuthenticateLogin(string emailId, string password)
        //{

            


        //    EvincePayrollService ws = new EvincePayrollService(ServiceTypes.Employee);
        //    EmployeeData employeeData = ws.AuthenticateLogin(emailId, password);
        //    //List<ExperienceData> experinceList = ws.GetExperinceByUserId(employeeData.Email,employeeData.ID.ToString());

        //    if (employeeData != null)
        //    {
        //        Session["EmployeeData"] = employeeData;

        //        if (employeeData.UserRoleId.ToString() == Constants.ADMIN_ROLE_ID)
        //        {
        //            return RedirectToAction("LeaveRequestsAdmin", "LeaveRequests");
        //        }
        //        if (employeeData.UserRoleId.ToString() != Constants.ADMIN_ROLE_ID)
        //        {
        //            Session["Templates"] = ws.GetPageTemplateList();
        //            return RedirectToAction("GetUserProfile", "Account");
        //        }



        //        return View();
        //        //return Json(new { employeeInformation = Session["EmployeeData"] }, JsonRequestBehavior.AllowGet);

        //    }
        //    else
        //    {
        //        ViewBag.ErrorMessage = "Login failed";
        //        return View("Login");

        //        //return Json(new { Result = "Login failed" }, JsonRequestBehavior.AllowGet);
        //    }



        //}

        //public ActionResult Logout()
        //{
        //    try
        //    {
        //        EmployeeData employeeData = (EmployeeData)Session["EmployeeData"];
        //        if (employeeData != null)
        //        {
        //            EvincePayrollService ws = new EvincePayrollService(ServiceTypes.Employee);
        //            bool employeeLogout = ws.Logout(employeeData.Email, employeeData.Password);
        //            Session["EmployeeData"] = null;
        //            //if (employeeLogout == true)
        //            //{
        //            //    return Json(new { Status = "Success" }, JsonRequestBehavior.AllowGet);
        //            //}
        //        }
        //    }
        //    catch (Exception ex)
        //    {

        //        LogEngine.Log(ex.Message);
        //        Response.Write(ex);
        //        throw;
        //    }

        //    return RedirectToAction("Login");
        //    //return View();
        //}



    }
}
